/**
 * 猫币定期流水管理初始化
 */
var LogStatedcc = {
    id: "LogStatedccTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
LogStatedcc.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle', width:30, formatter:function (value,row,index) {
                    return index+1;
                }},
            {title: '目标用户手机号', field: 'userPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '发起用户手机号', field: 'fromPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '对应订单号', field: 'orderNo', visible: true, align: 'center', valign: 'middle'},
            {title: '操作前的数量', field: 'preStatedcc', visible: true, align: 'center', valign: 'middle'},
            {title: '流水标志', field: 'statedccType', visible: true, align: 'center', valign: 'middle',formatter:LogStatedcc.stateccType},
            {title: '变化的数量', field: 'statedcc', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'},
            //{title: '有效状态 1有效 0删除', field: 'dataFlag', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '类型', field: 'type', visible: true, align: 'center', valign: 'middle',formatter:LogStatedcc.type}
    ];
};

//用户ID 0为平台
LogStatedcc.op = function(value){
    if(value == 0 || value == '' || typeof value == 'undefined'){
        value = '平台';
    }
    return value;

}
//流水标志
LogStatedcc.stateccType = function(value){
    var result = '';
    if(value == -1){
        result = '减少';
    }else if(value == 1){
        result = '增加';
    }
    return result;
}

LogStatedcc.type = function(value){
    return value;
}

/**
 * 检查是否选中
 */
LogStatedcc.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        LogStatedcc.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加猫币定期流水
 */
LogStatedcc.openAddLogStatedcc = function () {
    var index = layer.open({
        type: 2,
        title: '添加猫币定期流水',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/logStatedcc/logStatedcc_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看猫币定期流水详情
 */
LogStatedcc.openLogStatedccDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '猫币定期流水详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/logStatedcc/logStatedcc_update/' + LogStatedcc.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除猫币定期流水
 */
LogStatedcc.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/logStatedcc/delete", function (data) {
            Feng.success("删除成功!");
            LogStatedcc.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("logStatedccId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询猫币定期流水列表
 */
LogStatedcc.search = function () {
    var queryData = {};
    queryData['orderNo'] = $("#orderNo").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    LogStatedcc.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = LogStatedcc.initColumn();
    var table = new BSTable(LogStatedcc.id, "/logStatedcc/list", defaultColunms);
    table.setPaginationType("server");
    LogStatedcc.table = table.init();
});
